Remove borrowed pointer in Config
authorAlex Crichton <alex@alexcrichton.com>
Mon, 18 May 2015 22:33:04 +0000 (15:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 18 May 2015 22:33:04 +0000 (15:33 -0700)
Not having a lifetime parameter on the ubiquitous Config structure allows a
great deal of other lifetime annotations to be removed and should make dealing
with storage of Config in a structure much easier (only one lifetime to deal
with, not two).

15 files changed:
src/cargo/core/registry.rs
src/cargo/lib.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_doc.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_test.rs
src/cargo/sources/git/source.rs
src/cargo/sources/path.rs
src/cargo/sources/registry.rs
src/cargo/util/config.rs
src/cargo/util/toml.rs

index d6d4e898452b2214464d0cf6127522f202137472..3bd5e6a60583f881c1eff3a78c9a569dcff1669c 100644 (file)
@@ -32,9 +32,9 @@ impl Registry for Vec<Summary> {
 /// `SourceMap` structure contained within which is a mapping of a `SourceId` to
 /// a `Source`. Each `Source` in the map has been updated (using network
 /// operations if necessary) and is ready to be queried for packages.
-pub struct PackageRegistry<'a, 'b: 'a> {
-    sources: SourceMap<'a>,
-    config: &'a Config<'b>,
+pub struct PackageRegistry<'cfg> {
+    sources: SourceMap<'cfg>,
+    config: &'cfg Config,
 
     // A list of sources which are considered "overrides" which take precedent
     // when querying for packages.
@@ -67,8 +67,8 @@ enum Kind {
     Normal,
 }
 
-impl<'a, 'b> PackageRegistry<'a, 'b> {
-    pub fn new(config: &'a Config<'b>) -> PackageRegistry<'a, 'b> {
+impl<'cfg> PackageRegistry<'cfg> {
+    pub fn new(config: &'cfg Config) -> PackageRegistry<'cfg> {
         PackageRegistry {
             sources: SourceMap::new(),
             source_ids: HashMap::new(),
@@ -100,7 +100,7 @@ impl<'a, 'b> PackageRegistry<'a, 'b> {
         Ok(ret)
     }
 
-    pub fn move_sources(self) -> SourceMap<'a> {
+    pub fn move_sources(self) -> SourceMap<'cfg> {
         self.sources
     }
 
@@ -275,7 +275,7 @@ impl<'a, 'b> PackageRegistry<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Registry for PackageRegistry<'a, 'b> {
+impl<'cfg> Registry for PackageRegistry<'cfg> {
     fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
         let overrides = try!(self.query_overrides(dep));
 
index 904f4d48e9d6c44ff9ad5bfbe1c6e6ba2c32b481..d2b01e92c93474840f1e7218ef473574460b6370 100644 (file)
@@ -92,16 +92,20 @@ fn process<V, F>(mut callback: F)
     where F: FnMut(&[String], &Config) -> CliResult<Option<V>>,
           V: Encodable
 {
-    let mut shell = shell(true);
-    process_executed((|| {
-        let config = try!(Config::new(&mut shell));
+    let mut config = None;
+    let result = (|| {
+        config = Some(try!(Config::new(shell(true))));
         let args: Vec<_> = try!(env::args_os().map(|s| {
             s.into_string().map_err(|s| {
                 human(format!("invalid unicode in argument: {:?}", s))
             })
         }).collect());
-        callback(&args, &config)
-    })(), &mut shell)
+        callback(&args, config.as_ref().unwrap())
+    })();
+    let mut verbose_shell = shell(true);
+    let mut shell = config.as_ref().map(|s| s.shell());
+    let shell = shell.as_mut().map(|s| &mut **s).unwrap_or(&mut verbose_shell);
+    process_executed(result, shell)
 }
 
 pub fn process_executed<T>(result: CliResult<Option<T>>, shell: &mut MultiShell)
@@ -113,7 +117,7 @@ pub fn process_executed<T>(result: CliResult<Option<T>>, shell: &mut MultiShell)
             let encoded = json::encode(&encodable).unwrap();
             println!("{}", encoded);
         }
-        _ => {}
+        Ok(None) => {}
     }
 }
 
index cbeb3e61b7ab62eaa15499f237768ce2f1796c75..dbbf0412c91780d96e3d06fd9d26d3393f3922c6 100644 (file)
@@ -9,10 +9,10 @@ use sources::PathSource;
 use util::{CargoResult, human, ChainError, Config};
 use ops::{self, Layout, Context, BuildConfig, Kind};
 
-pub struct CleanOptions<'a, 'b: 'a> {
+pub struct CleanOptions<'a> {
     pub spec: Option<&'a str>,
     pub target: Option<&'a str>,
-    pub config: &'a Config<'b>,
+    pub config: &'a Config,
 }
 
 /// Cleans the project from build artifacts.
index f2b276cf7ee1b1716c535f1f0a14492a133967ba..74137e9efbc23bf3a5abe624792bad807aac09f2 100644 (file)
@@ -37,8 +37,8 @@ use util::config::{ConfigValue, Config};
 use util::{CargoResult, internal, human, ChainError, profile};
 
 /// Contains informations about how a package should be compiled.
-pub struct CompileOptions<'a, 'b: 'a> {
-    pub config: &'a Config<'b>,
+pub struct CompileOptions<'a> {
+    pub config: &'a Config,
     /// Number of concurrent jobs to use.
     pub jobs: Option<u32>,
     /// The target platform to compile for (example: `i686-unknown-linux-gnu`).
index 63ced9a12e3475dab0a1bb47d7f9488c5600cb37..5c2439e87510cb790239f5132e53eb1e361aac00 100644 (file)
@@ -9,9 +9,9 @@ use ops;
 use sources::PathSource;
 use util::{CargoResult, human};
 
-pub struct DocOptions<'a, 'b: 'a> {
+pub struct DocOptions<'a> {
     pub open_result: bool,
-    pub compile_opts: ops::CompileOptions<'a, 'b>,
+    pub compile_opts: ops::CompileOptions<'a>,
 }
 
 pub fn doc(manifest_path: &Path,
index 2c97a3dd36b5a8c07cba2f97d8827a9938774125..e120104391958dc0db8d28f8a985187a86f8f2f3 100644 (file)
@@ -10,8 +10,8 @@ use sources::{PathSource};
 use util::config::{Config};
 use util::{CargoResult, human};
 
-pub struct UpdateOptions<'a, 'b: 'a> {
-    pub config: &'a Config<'b>,
+pub struct UpdateOptions<'a> {
+    pub config: &'a Config,
     pub to_update: Option<&'a str>,
     pub precise: Option<&'a str>,
     pub aggressive: bool,
index 65e612f8fce49eea3028ce4d770e184762d840b8..3abb93e09afcff5b43b2d1bda6da0aac64b55152 100644 (file)
@@ -25,8 +25,8 @@ pub enum Platform {
     PluginAndTarget,
 }
 
-pub struct Context<'a, 'b: 'a> {
-    pub config: &'a Config<'b>,
+pub struct Context<'a> {
+    pub config: &'a Config,
     pub resolve: &'a Resolve,
     pub sources: &'a SourceMap<'a>,
     pub compilation: Compilation,
@@ -49,16 +49,16 @@ pub struct Context<'a, 'b: 'a> {
     profiles: &'a Profiles,
 }
 
-impl<'a, 'b: 'a> Context<'a, 'b> {
+impl<'a> Context<'a> {
     pub fn new(resolve: &'a Resolve,
                sources: &'a SourceMap<'a>,
                deps: &'a PackageSet,
-               config: &'a Config<'b>,
+               config: &'a Config,
                host: Layout,
                target_layout: Option<Layout>,
                root_pkg: &Package,
                build_config: BuildConfig,
-               profiles: &'a Profiles) -> CargoResult<Context<'a, 'b>> {
+               profiles: &'a Profiles) -> CargoResult<Context<'a>> {
         let target = build_config.requested_target.clone();
         let target = target.as_ref().map(|s| &s[..]);
         let (target_dylib, target_exe) = try!(Context::filename_parts(target));
index 0b1ac8aa1201ab9ad00bf0f479763813a18ff239..c7311849016d21abae4fb117e95abced2436b838 100644 (file)
@@ -39,11 +39,11 @@ pub type Preparation = (Freshness, Work, Work);
 /// This function will calculate the fingerprint for a target and prepare the
 /// work necessary to either write the fingerprint or copy over all fresh files
 /// from the old directories to their new locations.
-pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
-                              pkg: &'a Package,
-                              target: &'a Target,
-                              profile: &'a Profile,
-                              kind: Kind) -> CargoResult<Preparation> {
+pub fn prepare_target<'a>(cx: &mut Context<'a>,
+                          pkg: &'a Package,
+                          target: &'a Target,
+                          profile: &'a Profile,
+                          kind: Kind) -> CargoResult<Preparation> {
     let _p = profile::start(format!("fingerprint: {} / {}",
                                     pkg.package_id(), target.name()));
     let new = dir(cx, pkg, kind);
@@ -131,12 +131,12 @@ impl Fingerprint {
 ///
 /// Information like file modification time is only calculated for path
 /// dependencies and is calculated in `calculate_target_fresh`.
-fn calculate<'a, 'b>(cx: &mut Context<'a, 'b>,
-                     pkg: &'a Package,
-                     target: &'a Target,
-                     profile: &'a Profile,
-                     kind: Kind)
-                     -> CargoResult<Fingerprint> {
+fn calculate<'a>(cx: &mut Context<'a>,
+                 pkg: &'a Package,
+                 target: &'a Target,
+                 profile: &'a Profile,
+                 kind: Kind)
+                 -> CargoResult<Fingerprint> {
     let key = (pkg.package_id(), target, profile, kind);
     match cx.fingerprints.get(&key) {
         Some(s) => return Ok(s.clone()),
index 5986693d019a15776e54065b8f9aa788e3862078..24f160393e3fd454de33c8abeb23f7ee42079c2f 100644 (file)
@@ -77,15 +77,15 @@ pub fn rustc_version() -> CargoResult<(String, String)> {
 
 // Returns a mapping of the root package plus its immediate dependencies to
 // where the compiled libraries are all located.
-pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
-                               pkg: &'a Package,
-                               deps: &PackageSet,
-                               resolve: &'a Resolve,
-                               sources: &'a SourceMap<'a>,
-                               config: &'a Config<'b>,
-                               build_config: BuildConfig,
-                               profiles: &'a Profiles)
-                               -> CargoResult<Compilation> {
+pub fn compile_targets<'a>(targets: &[(&'a Target, &'a Profile)],
+                           pkg: &'a Package,
+                           deps: &PackageSet,
+                           resolve: &'a Resolve,
+                           sources: &'a SourceMap<'a>,
+                           config: &'a Config,
+                           build_config: BuildConfig,
+                           profiles: &'a Profiles)
+                           -> CargoResult<Compilation> {
     if targets.is_empty() {
         return Ok(Compilation::new(pkg))
     }
@@ -181,10 +181,10 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
     Ok(cx.compilation)
 }
 
-fn compile<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
-                   pkg: &'a Package,
-                   cx: &mut Context<'a, 'b>,
-                   jobs: &mut JobQueue<'a>) -> CargoResult<()> {
+fn compile<'a>(targets: &[(&'a Target, &'a Profile)],
+               pkg: &'a Package,
+               cx: &mut Context<'a>,
+               jobs: &mut JobQueue<'a>) -> CargoResult<()> {
     debug!("compile_pkg; pkg={}", pkg);
     let profiling_marker = profile::start(format!("preparing: {}", pkg));
 
@@ -292,10 +292,10 @@ fn compile<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
     Ok(())
 }
 
-fn prepare_init<'a, 'b>(cx: &mut Context<'a, 'b>,
-                        pkg: &'a Package,
-                        jobs: &mut JobQueue<'a>,
-                        visited: &mut HashSet<&'a PackageId>) {
+fn prepare_init<'a>(cx: &mut Context<'a>,
+                    pkg: &'a Package,
+                    jobs: &mut JobQueue<'a>,
+                    visited: &mut HashSet<&'a PackageId>) {
     if !visited.insert(pkg.package_id()) { return }
 
     // Set up all dependencies
index b4132239fcc55c707eaf0796a8e099f63c17cb10..360d1b7d40fe0152a2364c9711f4e27cef52d871 100644 (file)
@@ -6,8 +6,8 @@ use sources::PathSource;
 use ops::{self, ExecEngine, ProcessEngine, Compilation};
 use util::{self, CargoResult, ProcessError};
 
-pub struct TestOptions<'a, 'b: 'a> {
-    pub compile_opts: ops::CompileOptions<'a, 'b>,
+pub struct TestOptions<'a> {
+    pub compile_opts: ops::CompileOptions<'a>,
     pub no_run: bool,
 }
 
index c186c8e75b6c4a37dbdab7929e3cf72692c4b2e2..10a722cca313e7a636b74f7c5b54fd53c26c09d9 100644 (file)
@@ -14,20 +14,20 @@ use sources::git::utils::{GitRemote, GitRevision};
 
 /* TODO: Refactor GitSource to delegate to a PathSource
  */
-pub struct GitSource<'a, 'b:'a> {
+pub struct GitSource<'cfg> {
     remote: GitRemote,
     reference: GitReference,
     db_path: PathBuf,
     checkout_path: PathBuf,
     source_id: SourceId,
-    path_source: Option<PathSource<'a, 'b>>,
+    path_source: Option<PathSource<'cfg>>,
     rev: Option<GitRevision>,
-    config: &'a Config<'b>,
+    config: &'cfg Config,
 }
 
-impl<'a, 'b> GitSource<'a, 'b> {
+impl<'cfg> GitSource<'cfg> {
     pub fn new(source_id: &SourceId,
-               config: &'a Config<'b>) -> GitSource<'a, 'b> {
+               config: &'cfg Config) -> GitSource<'cfg> {
         assert!(source_id.is_git(), "id is not git, id={}", source_id);
 
         let reference = match source_id.git_reference() {
@@ -141,7 +141,7 @@ pub fn canonicalize_url(url: &Url) -> Url {
     return url;
 }
 
-impl<'a, 'b> Debug for GitSource<'a, 'b> {
+impl<'cfg> Debug for GitSource<'cfg> {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         try!(write!(f, "git repo at {}", self.remote.url()));
 
@@ -152,7 +152,7 @@ impl<'a, 'b> Debug for GitSource<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Registry for GitSource<'a, 'b> {
+impl<'cfg> Registry for GitSource<'cfg> {
     fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
         let src = self.path_source.as_mut()
                       .expect("BUG: update() must be called before query()");
@@ -160,7 +160,7 @@ impl<'a, 'b> Registry for GitSource<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Source for GitSource<'a, 'b> {
+impl<'cfg> Source for GitSource<'cfg> {
     fn update(&mut self) -> CargoResult<()> {
         let actual_rev = self.remote.rev_for(&self.db_path, &self.reference);
         let should_update = actual_rev.is_err() ||
index 9ccad77ad96559fbb0536253dcf48c4ae331baeb..16681226e1eac84b1da4e266720fb6a5cd0f2022 100644 (file)
@@ -12,19 +12,19 @@ use ops;
 use util::{self, CargoResult, internal, internal_error, human, ChainError};
 use util::{MTime, Config};
 
-pub struct PathSource<'a, 'b: 'a> {
+pub struct PathSource<'cfg> {
     id: SourceId,
     path: PathBuf,
     updated: bool,
     packages: Vec<Package>,
-    config: &'a Config<'b>,
+    config: &'cfg Config,
 }
 
 // TODO: Figure out if packages should be discovered in new or self should be
 // mut and packages are discovered in update
-impl<'a, 'b> PathSource<'a, 'b> {
-    pub fn for_path(path: &Path, config: &'a Config<'b>)
-                    -> CargoResult<PathSource<'a, 'b>> {
+impl<'cfg> PathSource<'cfg> {
+    pub fn for_path(path: &Path, config: &'cfg Config)
+                    -> CargoResult<PathSource<'cfg>> {
         trace!("PathSource::for_path; path={}", path.display());
         Ok(PathSource::new(path, &try!(SourceId::for_path(path)), config))
     }
@@ -32,8 +32,8 @@ impl<'a, 'b> PathSource<'a, 'b> {
     /// Invoked with an absolute path to a directory that contains a Cargo.toml.
     /// The source will read the manifest and find any other packages contained
     /// in the directory structure reachable by the root manifest.
-    pub fn new(path: &Path, id: &SourceId, config: &'a Config<'b>)
-               -> PathSource<'a, 'b> {
+    pub fn new(path: &Path, id: &SourceId, config: &'cfg Config)
+               -> PathSource<'cfg> {
         trace!("new; id={}", id);
 
         PathSource {
@@ -259,13 +259,13 @@ impl<'a, 'b> PathSource<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Debug for PathSource<'a, 'b> {
+impl<'cfg> Debug for PathSource<'cfg> {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         write!(f, "the paths source")
     }
 }
 
-impl<'a, 'b> Registry for PathSource<'a, 'b> {
+impl<'cfg> Registry for PathSource<'cfg> {
     fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
         let mut summaries: Vec<Summary> = self.packages.iter()
                                               .map(|p| p.summary().clone())
@@ -274,7 +274,7 @@ impl<'a, 'b> Registry for PathSource<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Source for PathSource<'a, 'b> {
+impl<'cfg> Source for PathSource<'cfg> {
     fn update(&mut self) -> CargoResult<()> {
         if !self.updated {
             let packages = try!(self.read_packages());
index 98d99576ddaf488a9365a63ab1eb86e88fcf4147..6dfdfcf6012cb0cabad5ca75a2e9db1183707471 100644 (file)
@@ -180,14 +180,14 @@ use ops;
 
 static DEFAULT: &'static str = "https://github.com/rust-lang/crates.io-index";
 
-pub struct RegistrySource<'a, 'b:'a> {
+pub struct RegistrySource<'cfg> {
     source_id: SourceId,
     checkout_path: PathBuf,
     cache_path: PathBuf,
     src_path: PathBuf,
-    config: &'a Config<'b>,
+    config: &'cfg Config,
     handle: Option<http::Handle>,
-    sources: Vec<PathSource<'a, 'b>>,
+    sources: Vec<PathSource<'cfg>>,
     hashes: HashMap<(String, String), String>, // (name, vers) => cksum
     cache: HashMap<String, Vec<(Summary, bool)>>,
     updated: bool,
@@ -226,9 +226,9 @@ struct RegistryDependency {
     kind: Option<String>,
 }
 
-impl<'a, 'b> RegistrySource<'a, 'b> {
+impl<'cfg> RegistrySource<'cfg> {
     pub fn new(source_id: &SourceId,
-               config: &'a Config<'b>) -> RegistrySource<'a, 'b> {
+               config: &'cfg Config) -> RegistrySource<'cfg> {
         let hash = hex::short_hash(source_id);
         let ident = source_id.url().host().unwrap().to_string();
         let part = format!("{}-{}", ident, hash);
@@ -472,7 +472,7 @@ impl<'a, 'b> RegistrySource<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Registry for RegistrySource<'a, 'b> {
+impl<'cfg> Registry for RegistrySource<'cfg> {
     fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
         // If this is a precise dependency, then it came from a lockfile and in
         // theory the registry is known to contain this version. If, however, we
@@ -511,7 +511,7 @@ impl<'a, 'b> Registry for RegistrySource<'a, 'b> {
     }
 }
 
-impl<'a, 'b> Source for RegistrySource<'a, 'b> {
+impl<'cfg> Source for RegistrySource<'cfg> {
     fn update(&mut self) -> CargoResult<()> {
         // If we have an imprecise version then we don't know what we're going
         // to look for, so we always atempt to perform an update here.
index f2a592530b4a249227c5e195288ca5e165daa56f..af567da54fa395540f2fce6e282a221599923ed9 100644 (file)
@@ -18,9 +18,9 @@ use util::toml as cargo_toml;
 
 use self::ConfigValue as CV;
 
-pub struct Config<'a> {
+pub struct Config {
     home_path: PathBuf,
-    shell: RefCell<&'a mut MultiShell>,
+    shell: RefCell<MultiShell>,
     rustc_version: String,
     /// The current host and default target of rustc
     rustc_host: String,
@@ -29,8 +29,8 @@ pub struct Config<'a> {
     cwd: PathBuf,
 }
 
-impl<'a> Config<'a> {
-    pub fn new(shell: &'a mut MultiShell) -> CargoResult<Config<'a>> {
+impl Config {
+    pub fn new(shell: MultiShell) -> CargoResult<Config> {
         let cwd = try!(env::current_dir().chain_error(|| {
             human("couldn't get the current directory of the process")
         }));
@@ -72,7 +72,7 @@ impl<'a> Config<'a> {
         self.home_path.join("registry").join("src")
     }
 
-    pub fn shell(&self) -> RefMut<&'a mut MultiShell> {
+    pub fn shell(&self) -> RefMut<MultiShell> {
         self.shell.borrow_mut()
     }
 
index 08bf5537f91fa4f2a6b5c062d7ea6b04f56ee0e5..41786df9a48eab20650f0cd4a1609bdcd5c7ab5b 100644 (file)
@@ -277,11 +277,11 @@ impl TomlProject {
     }
 }
 
-struct Context<'a, 'b, 'c: 'b> {
+struct Context<'a, 'b> {
     deps: &'a mut Vec<Dependency>,
     source_id: &'a SourceId,
     nested_paths: &'a mut Vec<PathBuf>,
-    config: &'b Config<'c>,
+    config: &'b Config,
 }
 
 // These functions produce the equivalent of specific manifest entries. One